<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Hello word</title>
    <script src='../vue.js'></script>
</head>

<body>
    <div id="app">
        <input type="text" v-model="inputeValue">
        <button v-on:click="handleBtnClick">提交</button>
        <ul>
            <!-- <li v-for="item in list">{{item}}</li> -->
            <todoitem v-bind:content="item" v-bind:index="index" v-for="(item,index) in list"
                @delete="handleItemDelete"></todoitem>
        </ul>

    </div>
</body>

</html>
<script>
    // 全局组件
    // Vue.component("todoitem", {
    //     props: ['content'],
    //     template: "<li>{{content}}</li>"
    // })

    // 局部组件
    var todoitem = {
        props: ['content', 'index'],
        template: "<li @click='handleItemClick'>{{content}}</li>",
        methods: {
            handleItemClick: function () {
                this.$emit("delete", this.index)
            }
        }
    }
    var app = new Vue({
        el: '#app',
        components: {
            todoitem: todoitem
        },
        data: {
            list: [],
            inputeValue: ''
        },
        methods: {
            handleBtnClick: function () {
                this.list.push(this.inputeValue);
                this.inputeValue = ''
            },
            handleItemDelete: function (index) {
                this.list.splice(index, 1)
            }
        }
    })
</script>